package cm.android.mytodoit.view;

import android.app.Activity;
import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.EditText;
import android.widget.Toast;
import cm.android.mytodoit.R;
import cm.android.mytodoit.controller.Todo_SQLOpenHelper;
import cm.android.mytodoit.model.TodoElement;

public class GenerateTodoView extends Activity {

	private EditText title, description, expirationdate, priority;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.generatetodoview);

		title = (EditText) findViewById(R.id.et_generatetodoview_title);
		description = (EditText) findViewById(R.id.et_generateview_description);
		expirationdate = (EditText) findViewById(R.id.et_generateview_expirationdate);
		priority = (EditText) findViewById(R.id.et_generateview_priority);
	}

	public void onButtonClick(View view) {
		
		SQLiteDatabase database = new Todo_SQLOpenHelper(this).getReadableDatabase();
		
		switch (view.getId()) {
		case R.id.bu_generateview_save:
			
			if ((!(title.getText().toString().equals("")))&& (!(priority.getText().toString().equals("")))) {
				
			
			try{
				
			ContentValues values = new ContentValues();
			
			values.put(TodoElement.TC_TITLE,title.getText().toString());
			values.put(TodoElement.TC_DESCRIPTION, description.getText().toString());
			values.put(TodoElement.TC_EXPIRATIONDATE, expirationdate.getText().toString());
			values.put(TodoElement.TC_PRIORITY, priority.getText().toString());
						
			database.insert(TodoElement.TABLE_NAME, null, values);
			
			Toast.makeText(this, "New Todo insert", Toast.LENGTH_SHORT).show();
			
			}catch (Exception e) {
				Toast.makeText(this, "db instert failed", Toast.LENGTH_SHORT).show();	
			}
			this.finish();			
			}
		}
	}
}
